package com.hzy.admin.controller.core;

import com.hzy.admin.controller.ApiBaseController;
import com.hzy.admin.repository.entity.system.SysMenu;
import com.hzy.admin.services.system.ISysUserService;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;

import java.util.List;
import java.util.Map;

/**
 * 主页
 *
 * @author hzy
 */
@Controller
public class MainController extends ApiBaseController<ISysUserService> {
    public MainController(ISysUserService sysUserService) {
        super("", sysUserService);
    }

    /**
     * 框架页面
     *
     * @param model
     * @return
     */
    @RequestMapping(value = {"/", "/admin"})
    public String main(Model model) {
        List<SysMenu> sysMenus = this.sysMenuService.getMenusByRoleId();
        List<Map<String, Object>> sysMenusMap = this.sysMenuService.menusToListMap("", sysMenus);
        model.addAttribute("user", this.service.getUserInfo());
        model.addAttribute("menus", sysMenusMap);
        return this.view("main");
    }

    /**
     * 主页
     *
     * @return
     */
    @GetMapping("/admin/home")
    public String home() {
        return this.view("home");
    }

}
